package cn.melonlib.nars.names.model.views;

import cn.melonlib.cores.commons.model.entity.TenantRecordEntity;
import cn.melonlib.cores.model.anno.ModelComment;
import cn.melonlib.nars.names.model.enmus.NamesType;
import cn.melonlib.nars.names.model.entity.MelonFile;
import cn.melonlib.nars.names.model.entity.MelonNames;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

@Data
@EqualsAndHashCode(callSuper = true)
public class MelonNamesVo extends TenantRecordEntity {

    public MelonNamesVo(MelonNames names) {
        BeanUtils.copyProperties(names,this);
        if(names instanceof MelonFile){
            ObjectMapper objectMapper=new ObjectMapper();
            try {
                this.ext = objectMapper.readValue(names.exts(), MelonNamesExtVo.class);
            }catch (Exception e){

            }
        }
    }

    @ModelComment(value = "名称",required = true)
    private String name;

    @ModelComment("路径")
    private String path;

    @ModelComment("名称类型")
    private NamesType namesType=NamesType.DIRECTORY;

    @ModelComment("扩展信息")
    private MelonNamesExtVo ext;
}
